<?php
class Order_Dao{

	
	function __construct(){
			$koneksi = new Koneksi();
			$koneksi->_connect();
	}
	
	function add(Order $order){
		
		$sql = "
			INSERT 
			INTO
			orders
			(
				id_konsumen,
				tanggal,
				total,
				status
			)
			VALUES
			(
				'".$order->id_konsumen."',
				'".$order->tanggal."',
				'".$order->total."',
				'".$order->status."'
			)
		";
		
		mysql_query($sql);
		
	}
	
	function get($orderid){
	
		$sql = "
		SELECT
		*
		FROM
		orders
		WHERE
		orderid = '".$orderid."'
		";
		
		$order = false;
		
		$res = mysql_query($sql);
		
		if($res){
		
			$row = mysql_fetch_assoc($res);
		
			$order = new Order();
				$order->orderid = $row['orderid'];
				$order->id_konsumen = $row['id_konsumen'];
				$order->tanggal = $row['tanggal'];
				$order->total = $row['total'];
				$order->status = $row['status'];
		}
		
		return $order;
	}
	
	function get_konsumen($id_konsumen){

		$sql = "
		SELECT
		*
		FROM
		orders
		WHERE
		id_konsumen='".$id_konsumen."' 
		";
		
		$order = false;
		
		$res = mysql_query($sql);
		
		if($res){
		
			$row = mysql_fetch_assoc($res);
		
				$order = new Order();

				$order->orderid = $row['orderid'];
				$order->id_konsumen = $row['id_konsumen'];
				$order->tanggal = $row['tanggal'];
				$order->total = $row['total'];
				$order->status = $row['status'];
		}
		
		return $order;
	}
	
	function get_status(){
	
		
		$sql = "
		SELECT
		*
		FROM
		orders
		WHERE
		status = '1'
		";
		
		$list_status = array();
		
		$res = mysql_query($sql);
		
		if($res){
		
			while($row = mysql_fetch_assoc($res)){
		
			$status = new Order();
				$status->orderid = $row['orderid'];
				$status->id_konsumen = $row['id_konsumen'];
				$status->tanggal = $row['tanggal'];
				$status->total = $row['total'];
				$status->status = $row['status'];
				$list_status[] = $status;
		}
		}
		return $list_status;
	}
	function get_status2(){
	
		
		$sql = "
		SELECT
		*
		FROM
		orders
		WHERE
		status = '2'
		";
		
		$list_status = array();
		
		$res = mysql_query($sql);
		
		if($res){
		
			while($row = mysql_fetch_assoc($res)){
		
			$status = new Order();
				$status->orderid = $row['orderid'];
				$status->id_konsumen = $row['id_konsumen'];
				$status->tanggal = $row['tanggal'];
				$status->total = $row['total'];
				$status->status = $row['status'];
				$list_status[] = $status;
		}
		}
		return $list_status;
	}
	function get_status3(){
	
		
		$sql = "
		SELECT
		*
		FROM
		orders
		WHERE
		status = '3'
		";
		
		$list_status = array();
		
		$res = mysql_query($sql);
		
		if($res){
		
			while($row = mysql_fetch_assoc($res)){
		
			$status = new Order();
				$status->orderid = $row['orderid'];
				$status->id_konsumen = $row['id_konsumen'];
				$status->tanggal = $row['tanggal'];
				$status->total = $row['total'];
				$status->status = $row['status'];
				$list_status[] = $status;
		}
		}
		return $list_status;
	}
	function get_all(){
	
		
		$sql = "
		SELECT
		*
		FROM
		orders
		";
		
		$list_orders = array();
		
		$res = mysql_query($sql);
		if($res){
			while($row = mysql_fetch_assoc($res)){
			
				$order = new Order();
				
				$order->orderid = $row['orderid'];
				$order->id_konsumen = $row['id_konsumen'];
				$order->tanggal = $row['tanggal'];
				$order->total = $row['total'];
				$order->status = $row['status'];
			    $list_orders[] = $order;
			}
		}
		return $list_orders;
	
	}
	function edit_status2($orderid){
		$sql ="
			UPDATE 
			orders
			SET
			status='2'
			WHERE 
			orderid ='$orderid'
		";
		mysql_query($sql);
	
	}
	function edit_status3($orderid){
		$sql ="
			UPDATE 
			orders
			SET
			status='3'
			WHERE 
			orderid ='$orderid'
		";
		mysql_query($sql);
	
	}
	}
class Order{

	var $orderid;
	var $id_konsumen;
	var $tanggal;
	var $total;
	var $status;
	}